package com.ruoyi.project.module.group.domain;

import com.google.common.collect.Lists;
import com.ruoyi.project.module.applicationProperty.domain.ApplicationProperty;

import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;

/**
 * com.ruoyi.project.module.group.domain.ApplicationPropertyTree
 * <br>
 *
 * @author 蒋カイセキ    Japan-Tokyo  19-4-16 上午10:40<br>
 * ブログ http://www.shoukaiseki.top/<br>
 * E-メール jiang28555@Gmail.com<br>
 **/
public class ApplicationPropertyTree extends ApplicationProperty {

    //关联的配置组属性
    private GroupPropertyTree gpTree;


    /**
     * 存放父级
     */
    private ApplicationPropertyTree parentTree;


    /**
     * 存放子级
     */
    private List<ApplicationPropertyTree> childrenList;

    public GroupPropertyTree getGpTree() {
        return gpTree;
    }

    public void setGpTree(GroupPropertyTree gpTree) {
        this.gpTree = gpTree;
    }

    public ApplicationPropertyTree getParentTree() {
        return parentTree;
    }

    public void setParentTree(ApplicationPropertyTree parentTree) {
        this.parentTree = parentTree;
    }

    public List<ApplicationPropertyTree> getChildrenList() {
        return childrenList;
    }

    public void setChildrenList(List<ApplicationPropertyTree> childrenList) {
        this.childrenList = childrenList;
    }

    public void addChildrenList(ApplicationPropertyTree... childrenList) {
        if(this.childrenList==null){
            this.childrenList= Lists.newArrayList();
        }
        for (ApplicationPropertyTree applicationPropertyTree : childrenList) {
            Stream<ApplicationPropertyTree> stream = this.childrenList.stream().filter(u -> Objects.equals(u.getConfigApplicationPropertyId(), applicationPropertyTree.getConfigApplicationPropertyId()));
            Optional<ApplicationPropertyTree> first = stream.findFirst();
            if (!first.isPresent()) {
                this.childrenList.add(applicationPropertyTree);
            }
        }
    }
}
